import { Tools } from "../../common/Tools";

const {ccclass, property} = cc._decorator;

@ccclass
export default class RectOpacity extends cc.Component {
    onEnable() {
        for (let i = 0; i < this.node.children.length; i++) {
            let node = this.node.children[i];
            this.runOpaTween(node);
        }
    }
    runOpaTween(node:cc.Node){
        node.opacity = 0;
        cc.Tween.stopAllByTarget(node);
        
        cc.tween(node)
        .delay( Math.random() * 0.2 )
        .call( () => {
            node.position = cc.v3( Tools.random(-this.node.width/2,this.node.width/2) , Tools.random( -this.node.height/2 , this.node.height/2 ) );
        } )
        .to(  0.3 , { opacity:255 } )
        .delay( 0.2)
        .to(  0.2 , { opacity:0 } )
        .union().repeatForever().start();
    };
}
